AVM2: Implement avmplus' sort algorithm instead of using the standard Rust sort.#17846
Merged
torokati44 merged 2 commits intoruffle-rs:masterfrom Sep 11, 2024
Merged
AVM2: Implement avmplus' sort algorithm instead of using the standard Rust sort.#17846torokati44 merged 2 commits intoruffle-rs:masterfrom
torokati44 merged 2 commits intoruffle-rs:masterfrom
Conversation
Member
Aaron1011
approved these changes
Sep 11, 2024
4ccfafa to
3aa7796
Compare
adrian17
approved these changes
Sep 11, 2024
These tests fail because we do not implement the exact same algorithm as Flash Player: - in AVM1, the test produces a different result - in AVM2, the test panics because Rust's sort doesn't accomodate non-Ord comparison functions
…fle-rs#17812 Replace the use of Rust's standard sort in `Array.sort` and `sortOn` by a port of avmplus' QuickSort algorithm. This avoid panics on Rust >=1.81 when `Array.sort` is called with a non-Ord comparison function, and will always produce the same result as Flash Player.
3aa7796 to
5f3851a
Compare
|
I wonder if this change is a good fit for running arbitrary user-code. It's trivial to hit quadratic run-time, e.g: let len = 1_000_000;
let mut v = (0..len as i32).map(|val| val % 2).collect::<Vec<i32>>();
let _ = qsort(&mut v, &mut |a, b| -> Result<Ordering, ()> { Ok(a.cmp(b)) });I guess if you are going for bug-for-bug compatibility with the avmplus code this is the correct choice. |
moulins
added a commit
to moulins/ruffle
that referenced
this pull request
Sep 13, 2024
This was forgotten in ruffle-rs#17846.
torokati44
pushed a commit
that referenced
this pull request
Sep 13, 2024
This was forgotten in #17846.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the use of Rust's standard sort in
Array.sortandsortOnby a port of avmplus' QuickSort algorithm. This avoid panics on Rust >=1.81 whenArray.sortis called with a non-Ord comparison function, and will always produce the same result as Flash Player.This also adds a test for AVM1 and AVM2 for "sorting" an array with a random comparison function, that check both the sorted result and the exact sequence of comparisons done by the algorithm. Currently, this test only passes for AVM2; I wasn't able to find which modifications to apply to the AVM1 quicksort to produce the correct results.